import { createRouter, createWebHistory } from "vue-router";
import { serveTitile } from "../api/api"
const routes = [

  {
    name: "downloaddetails",
    path: "/downloaddetails",
    component: () =>
      import("../view/download/componet/downloaddetails.vue"),
    meta: {
      name: "模板中心",
      breadcrumb: [
        { text: "模板中心", link: "/download" },
        { text: "详情", link: "/downloaddetails" },
      ],
    },
  },
  {
    name: "schooldetails",
    path: "/schooldetails",
    component: () =>
      import("../view/school/component/schooldetails.vue"),

  },

  {
    name: "evaluationadd",
    path: "/evaluationadd",
    component: () => import("../component/setting/home.vue"),
    meta: { name: "首页" },
  },
  {
    name: "evaluationedit",
    path: "/evaluationedit",
    component: () => import("../component/setting/edit.vue"),
    meta: { name: "首页" },
  },
  {
    name: "info",
    path: "/info",
    component: () => import("../component/setting/info.vue"),
    meta: { name: "首页" },
  },
  {
    name: "Home",
    path: "/home",
    component: () => import("../view/home/home.vue"),
    children: [
      {
        name: "index",
        path: "/index",
        component: () => import("../view/index/index.vue"),
        meta: { name: "首页" },
      },
      {
        name: "download",
        path: "/download",
        component: () => import("../view/download/download.vue"),
      },
      {
        name: "school",
        path: "/school",
        component: () => import("../view/school/school.vue"),
        meta: { name: "首页" },
      },



    ],

  },
  {
    name: "annual",
    path: "/annual",
    component: () => import("../view/annual/annual.vue"),
    meta: { name: "首页" },
  },

  {
    name: "annualdetails",
    path: "/annualdetails",
    component: () =>
      import("../view/annual/component/annualdetails.vue"),
    meta: {
      name: "模板中心",
      breadcrumb: [
        { text: "年度展示", link: "/annual" },
        { text: "详情", link: "/annualdetails" },
      ],
    },
  },
  {
    name: "teaching",
    path: "/teaching",
    component: () => import("../view/teaching/teaching.vue"),
    meta: { name: "首页" },
  },
  {
    name: "teaching",
    path: "/",
    component: () => import("../view/teaching/teaching.vue"),
    meta: { name: "首页" },
  },

  {
    name: "teachingDetails",
    path: "/teachingDetails",
    component: () =>
      import("../view/teaching/teachingDetails.vue"),
    meta: {
      name: "模板中心",
      breadcrumb: [
        { text: "年度展示", link: "/teaching" },
        { text: "详情", link: "/teachingDetails" },
      ],
    },
  },

];

const router = createRouter({
  history: createWebHistory(),
  routes,
});

let servetitle = ref('')
const gettitle = async () => {
  let res = await serveTitile({})
  servetitle.value = res.data.title
  document.title = servetitle.value
}
gettitle()

router.beforeEach((to, from, next) => {
  // console.log('跳转前',to)

  if (servetitle.value == '') {
    gettitle()
    next();
  } else {
    document.title = '2024年度教师职称推荐评审授课能力考核视频'
    next();
  }

});
router.afterEach((to, from) => {
  // console.log(to,from,next,'跳转后')
});

export default router;
